home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9287 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  53 lines

  1. Path: newshub.cts.com!usenet
  2. From: lboard@cts.com (Larry Board)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What is referencing good for?
  5. Date: Thu, 29 Feb 1996 05:42:34 GMT
  6. Organization: CTS Network Services
  7. Message-ID: <313539c9.4835024@news2.cts.com>
  8. References: <4goojd$a9g@wintermute.ecs.fullerton.edu>
  9. NNTP-Posting-Host: lboard.cts.com
  10.  
  11. On 25 Feb 1996 04:29:33 GMT, grosin@titan.fullerton.edu (Gil Rosin)
  12. wrote:
  13.  
  14. >I've been playing with referencing all day, and I can not find one use for it
  15. >that I can not do with pointers. What is referencing good for? I know about
  16. >reference parameters and I know about reference functions.
  17.  
  18. >Can someone give me a REAL world example of where I would use referencing
  19. >perhaps somewhere that I can not use pointers? 
  20.  
  21.  
  22. I ran across a slick use for references this morning while reading the
  23. Microsoft iostream class library reference.  It basically described
  24. how you could write your own manipulators using references.
  25.  
  26. The code below is a modification of the example they gave.  It
  27. basically creates two new manipulators called bold and normal.
  28. Assuming that ansi.sys is loaded, bold sets the display to high
  29. intensity, while normal turns it off.
  30.  
  31.  
  32. ------------------------------------------------------
  33. #include <iostream.h>
  34.  
  35. ostream& bold(ostream& os)
  36. {
  37.     return os << '\033' << "[1m";
  38. }
  39.  
  40. ostream& normal(ostream& os)
  41. {
  42.     return os << '\033' << "[0m";
  43. }
  44.  
  45. main()
  46. {
  47.     cout << "normal text " << bold << "bold text" << normal << "\n";
  48.     return(0);
  49. }
  50. ------------------------------------------------------
  51.  
  52.  
  53.